package top.gohigh.cameradata;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;

import com.orhanobut.logger.Logger;

import cn.jpush.android.api.JPushInterface;

public class LocalMsgReceiver extends BroadcastReceiver {
    private static final String TAG = "JIGUANG";
    @Override
    public void onReceive(Context context, Intent intent) {

        try{
            Bundle bundle=intent.getExtras();
            if(JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())){
                String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
                Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
                Intent msgIntent=new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
                msgIntent.putExtra("regId",regId);
                LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
            }

        }catch (Exception e){

        }
    }

    //send msg to MainActivity
    private void processCustomMessage(Context context, Bundle bundle) {
        if (MainActivity.isForeground) {
            String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
            Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
          //  msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);

            LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
        }
    }



}
